package 力扣日常刷题.木22二月.第18天224;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

/**
 * @author 帅小伙
 * @date 2022/2/24
 * @description
 */
public class Demo145字节跳动2018校招后端方向第二批2 {






    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), m = scanner.nextInt(), c = scanner.nextInt();
        HashSet<Integer> set = new HashSet<>();

        ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int num_i = scanner.nextInt();
            ArrayList<Integer> list = new ArrayList<>();
            for (int j = 0; j < num_i; j++) {
                list.add(scanner.nextInt());
            }
            lists.add(list);
        }

        for (int i = 0; i < n; i++) {
            ArrayList<Integer> list = lists.get(i);
            ArrayList<Integer> t = new ArrayList<>();
            for (Integer integer : list) {
                if(set.contains(integer))continue;
                t.add(integer);
            }
            if(t.size() == 0) continue;
            for (int j = i + 1; j < (i+m); j++) {
                HashSet<Integer> integers = new HashSet(lists.get(j%n));
                if(integers.isEmpty()) continue;
                for (Integer integer : t) {
                    if(integers.contains(integer)) {
                        set.add(integer);
                        integers.remove(integer);
                    }
                }
            }
        }
        System.out.println(set.size());
    }

}
